package service;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/demo3")
public class ServletDemo3  extends HttpServlet {
/*
* HttpServletRequest req:
* HttpServletResponse resp:
*都是服务器创建的，可以直接使用 req 封装了请求消息的内容
*
* */

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*1.获取请求方式
        *String getMethod();
        *
        *
        * */
        String method = req.getMethod();
        System.out.println(method);
        System.out.println("************");
/*2.获取虚拟目录
*String getContextPath();
* */
        String contextPath = req.getContextPath();
        System.out.println(contextPath);
        System.out.println("************");
        /*3.获取servlet路径 资源路径
        * String getServletPath();
        * */
        String servletPath = req.getServletPath();
        System.out.println(servletPath);
        System.out.println("************");
        /*4.获取get 方式的请求参数 name = zhangsan
        * String getQueryString();
        * */
        String queryString = req.getQueryString();
        System.out.println(queryString);
        System.out.println("************");
        /*5.获取请求urI：/servletdemo01/demo3

        *String getRequestURI();
        *
        * */
        String requestURI =req.getRequestURI();
        System.out.println(requestURI);
        System.out.println("************");

        StringBuffer requestURL = req.getRequestURL();
        System.out.println(requestURL);

        /*
        * URI:统一资源标识符：/serivcedemo/demo3
        * URL:统一资源定位符：http://localhost:8080/serivcedemo/demo3
        * */
    }
}
